/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.prov.soap.SoapTest;
/*     */ import com.zimbra.soap.admin.message.AddAccountAliasRequest;
/*     */ import com.zimbra.soap.admin.message.AddAccountAliasResponse;
/*     */ import com.zimbra.soap.admin.message.AddDistributionListMemberRequest;
/*     */ import com.zimbra.soap.admin.message.AddDistributionListMemberResponse;
/*     */ import com.zimbra.soap.admin.message.GetAccountMembershipRequest;
/*     */ import com.zimbra.soap.admin.message.GetAccountMembershipResponse;
/*     */ import com.zimbra.soap.admin.message.RemoveDistributionListMemberRequest;
/*     */ import com.zimbra.soap.admin.message.RemoveDistributionListMemberResponse;
/*     */ import com.zimbra.soap.admin.type.DLInfo;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ import org.junit.After;
/*     */ import org.junit.Before;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestDLMembership
/*     */   extends TestCase
/*     */ {
/*  47 */   private static String TEST_USER = "testuser1";
/*  48 */   private static String TEST_ALIAS = "testalias1";
/*  49 */   private static String TEST_DL = "testdl1";
/*     */   private static Account testUser;
/*     */   private static DistributionList testDL;
/*     */   
/*     */   @Before
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  57 */     cleanup();
/*     */     
/*  59 */     testUser = TestUtil.createAccount(TEST_USER);
/*     */     
/*  61 */     testDL = TestUtil.createDistributionList(TEST_DL);
/*     */   }
/*     */   
/*     */   @After
/*     */   public void tearDown() throws Exception
/*     */   {
/*  67 */     cleanup();
/*     */   }
/*     */   
/*     */   private void cleanup() throws Exception {
/*  71 */     TestUtil.deleteDistributionList(TEST_DL);
/*  72 */     TestUtil.deleteAccount(TEST_USER);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testAddMemberByName() {
/*     */     try {
/*  78 */       SoapTransport transport = TestUtil.getAdminSoapTransport();
/*     */       
/*  80 */       AddDistributionListMemberResponse addDLMemberResp = (AddDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new AddDistributionListMemberRequest(testDL.getId(), Collections.singleton(testUser.getName())));
/*     */       
/*  82 */       assertNotNull("AddDistributionListMemberResponse cannot be null", addDLMemberResp);
/*     */       
/*     */ 
/*  85 */       ArrayList<DistributionList> result = new ArrayList();
/*  86 */       GetAccountMembershipResponse resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/*  88 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/*  89 */       List<DLInfo> dlInfoList = resp.getDlList();
/*  90 */       assertTrue("Account is not a member of any DLs", dlInfoList.size() > 0);
/*  91 */       assertEquals("Account should be a member of the test DL only", ((DLInfo)dlInfoList.get(0)).getName(), testDL.getName());
/*     */     }
/*     */     catch (Exception e) {
/*  94 */       fail(e.getLocalizedMessage());
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testAddMemberByAlias()
/*     */   {
/*     */     try
/*     */     {
/* 103 */       SoapTransport transport = TestUtil.getAdminSoapTransport();
/*     */       
/* 105 */       AddAccountAliasResponse addAliasResp = (AddAccountAliasResponse)SoapTest.invokeJaxb(transport, new AddAccountAliasRequest(testUser.getId(), TestUtil.getAddress(TEST_ALIAS)));
/* 106 */       assertNotNull("AddAccountAliasResponse cannot be null", addAliasResp);
/* 107 */       Account acct = Provisioning.getInstance().getAccount(testUser.getId());
/* 108 */       assertNotNull(acct);
/* 109 */       assertNotNull("account's aliases are null", acct.getAliases());
/* 110 */       assertEquals("account has no aliases", acct.getAliases().length, 1);
/*     */       
/*     */ 
/* 113 */       AddDistributionListMemberResponse addDLMemberResp = (AddDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new AddDistributionListMemberRequest(testDL.getId(), Collections.singleton(TestUtil.getAddress(TEST_ALIAS))));
/*     */       
/* 115 */       assertNotNull("AddDistributionListMemberResponse cannot be null", addDLMemberResp);
/*     */       
/*     */ 
/* 118 */       GetAccountMembershipResponse resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/* 120 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/* 121 */       List<DLInfo> dlInfoList = resp.getDlList();
/* 122 */       assertTrue("Account is not a member of any DLs", dlInfoList.size() > 0);
/* 123 */       assertEquals("Account should be a member of the test DL only", ((DLInfo)dlInfoList.get(0)).getName(), testDL.getName());
/*     */     }
/*     */     catch (Exception e) {
/* 126 */       fail(e.getLocalizedMessage());
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testRemoveMemberByAlias()
/*     */   {
/*     */     try {
/* 134 */       SoapTransport transport = TestUtil.getAdminSoapTransport();
/*     */       
/* 136 */       AddAccountAliasResponse addAliasResp = (AddAccountAliasResponse)SoapTest.invokeJaxb(transport, new AddAccountAliasRequest(testUser.getId(), TestUtil.getAddress(TEST_ALIAS)));
/* 137 */       assertNotNull("AddAccountAliasResponse cannot be null", addAliasResp);
/* 138 */       Account acct = Provisioning.getInstance().getAccount(testUser.getId());
/* 139 */       assertNotNull(acct);
/* 140 */       assertNotNull("account's aliases are null", acct.getAliases());
/* 141 */       assertEquals("account has no aliases", acct.getAliases().length, 1);
/*     */       
/*     */ 
/* 144 */       AddDistributionListMemberResponse addDLMemberResp = (AddDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new AddDistributionListMemberRequest(testDL.getId(), Collections.singleton(TestUtil.getAddress(TEST_ALIAS))));
/*     */       
/* 146 */       assertNotNull("AddDistributionListMemberResponse cannot be null", addDLMemberResp);
/*     */       
/*     */ 
/* 149 */       ArrayList<DistributionList> result = new ArrayList();
/* 150 */       GetAccountMembershipResponse resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/* 152 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/* 153 */       List<DLInfo> dlInfoList = resp.getDlList();
/* 154 */       assertTrue("Account is not a member of any DLs", dlInfoList.size() > 0);
/* 155 */       assertEquals("Account should be a member of the test DL only", ((DLInfo)dlInfoList.get(0)).getName(), testDL.getName());
/*     */       
/*     */ 
/* 158 */       RemoveDistributionListMemberResponse rdlmresp = (RemoveDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new RemoveDistributionListMemberRequest(testDL.getId(), Arrays.asList(new String[] { TestUtil.getAddress(TEST_ALIAS) })));
/*     */       
/* 160 */       assertNotNull("RemoveDistributionListMemberRequest cannot be null", rdlmresp);
/*     */       
/*     */ 
/* 163 */       result = new ArrayList();
/* 164 */       resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/* 166 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/* 167 */       dlInfoList = resp.getDlList();
/* 168 */       assertTrue("Account should not be a member of any DLs", dlInfoList.size() == 0);
/*     */     }
/*     */     catch (Exception e) {
/* 171 */       fail(e.getLocalizedMessage());
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testRemoveMemberByName()
/*     */   {
/*     */     try {
/* 179 */       SoapTransport transport = TestUtil.getAdminSoapTransport();
/*     */       
/* 181 */       AddAccountAliasResponse addAliasResp = (AddAccountAliasResponse)SoapTest.invokeJaxb(transport, new AddAccountAliasRequest(testUser.getId(), TestUtil.getAddress(TEST_ALIAS)));
/* 182 */       assertNotNull("AddAccountAliasResponse cannot be null", addAliasResp);
/* 183 */       Account acct = Provisioning.getInstance().getAccount(testUser.getId());
/* 184 */       assertNotNull(acct);
/* 185 */       assertNotNull("account's aliases are null", acct.getAliases());
/* 186 */       assertEquals("account has no aliases", acct.getAliases().length, 1);
/*     */       
/*     */ 
/* 189 */       AddDistributionListMemberResponse addDLMemberResp = (AddDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new AddDistributionListMemberRequest(testDL.getId(), Collections.singleton(TestUtil.getAddress(TEST_ALIAS))));
/*     */       
/* 191 */       assertNotNull("AddDistributionListMemberResponse cannot be null", addDLMemberResp);
/*     */       
/*     */ 
/* 194 */       ArrayList<DistributionList> result = new ArrayList();
/* 195 */       GetAccountMembershipResponse resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/* 197 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/* 198 */       List<DLInfo> dlInfoList = resp.getDlList();
/* 199 */       assertTrue("Account is not a member of any DLs", dlInfoList.size() > 0);
/* 200 */       assertEquals("Account should be a member of the test DL only", ((DLInfo)dlInfoList.get(0)).getName(), testDL.getName());
/*     */       
/*     */ 
/* 203 */       RemoveDistributionListMemberResponse rdlmresp = (RemoveDistributionListMemberResponse)SoapTest.invokeJaxb(transport, new RemoveDistributionListMemberRequest(testDL.getId(), null, Arrays.asList(new String[] { TestUtil.getAddress(TEST_USER) })));
/*     */       
/* 205 */       assertNotNull("RemoveDistributionListMemberRequest cannot be null", rdlmresp);
/*     */       
/*     */ 
/* 208 */       result = new ArrayList();
/* 209 */       resp = (GetAccountMembershipResponse)SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
/*     */       
/* 211 */       assertNotNull("GetAccountMembershipRequest cannot be null", resp);
/* 212 */       dlInfoList = resp.getDlList();
/* 213 */       assertTrue("Account should not be a member of any DLs", dlInfoList.size() == 0);
/*     */     }
/*     */     catch (Exception e) {
/* 216 */       fail(e.getLocalizedMessage());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestDLMembership.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */